Skip to content

Fix PathUtils.IsSymlink throwing on common lstat failures#183

Merged
rmarinho merged 2 commits into
mainfrom
fix/pathutils-isymlink-error-handling
Jun 1, 2026
Merged

Fix PathUtils.IsSymlink throwing on common lstat failures#183
rmarinho merged 2 commits into
mainfrom
fix/pathutils-isymlink-error-handling

Conversation

@rmarinho
Copy link
Copy Markdown
Member

Summary

IsSymlink previously threw for any lstat failure, including file-not-found and permission-denied. These are expected when walking directory trees (e.g. IsSymlinkOrHasParentSymlink).

Now returns false for ENOENT (2), EACCES (13), and ENOTDIR (20), only throwing for genuinely unexpected errors.

Testing

Added PathUtilsTests with 4 tests verifying behavior for non-existent files, regular files, symlinks, and parent-symlink traversal.

Also adds InternalsVisibleTo for the test assembly.

Copilot AI review requested due to automatic review settings May 29, 2026 15:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts PathUtils.IsSymlink to treat common lstat failures (e.g., missing path / access denied) as non-exceptional and return false, improving robustness when walking directory trees. It also introduces NUnit coverage for the updated behavior and attempts to expose internals to the test assembly.

Changes:

  • Update PathUtils.IsSymlink to return false for specific errno values instead of throwing.
  • Add PathUtilsTests to validate symlink detection and non-existent-path behavior.
  • Add an InternalsVisibleTo entry intended to allow tests to access internal types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
Xamarin.MacDev/Xamarin.MacDev.csproj Adds InternalsVisibleTo for the tests assembly.
Xamarin.MacDev/PathUtils.cs Updates IsSymlink error handling for lstat failures.
tests/PathUtilsTests.cs Adds new NUnit tests for PathUtils behavior.

Comment thread Xamarin.MacDev/Xamarin.MacDev.csproj
Comment thread Xamarin.MacDev/PathUtils.cs
Comment thread tests/PathUtilsTests.cs
Comment thread tests/PathUtilsTests.cs Outdated
Comment thread tests/PathUtilsTests.cs
@rmarinho rmarinho force-pushed the fix/pathutils-isymlink-error-handling branch from a1ab463 to 172d659 Compare May 29, 2026 15:53
IsSymlink previously threw an exception for any lstat failure, including
ENOENT (file not found) and EACCES (permission denied). These are expected
non-exceptional conditions — especially when walking directory trees to check
for symlinks via IsSymlinkOrHasParentSymlink.

Now returns false for ENOENT, EACCES, and ENOTDIR, and only throws for
genuinely unexpected errno values. Uses named constants for clarity.

Also adds InternalsVisibleTo for the test project and new PathUtilsTests
(5 tests covering non-existent, regular, symlink, parent-walk, and ENOTDIR).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho rmarinho force-pushed the fix/pathutils-isymlink-error-handling branch from 172d659 to ae7c268 Compare May 29, 2026 17:25
- Remove unused 'using System;' from PathUtilsTests.cs
- Add IsSymlinkOrHasParentSymlink_ReturnsTrue_WhenParentIsSymlink test
  that creates a symlink directory and verifies parent traversal

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho rmarinho merged commit 00d5dfe into main Jun 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants